package com.ruoyi.job.task;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.job.mapper.UserReserveParkMapper;
import com.ruoyi.job.domain.*;
import com.ruoyi.job.mapper.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }


    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private SysUserNeedMapper sysUserNeedMapper;

    @Resource
    private UserStatisticsMapper userStatisticsMapper;

    @Resource
    private SpaceStatisticsMapper spaceStatisticsMapper;


    public void userStatistics(){
        UserStatistics statistics = new UserStatistics();
        /*总注册数*/
        long totalCount = sysUserMapper.selectSysUserListAll(null).size();

        statistics.setTotalCount(totalCount);

        /*已注册数*/
        long registerCount = totalCount -sysUserNeedMapper.selectSysUserNeedNotList();
        statistics.setRegisterCount(registerCount);

        /*未通过用户*/
        long failCount = sysUserNeedMapper.selectSysUserNeedNotCarryList();
        statistics.setFailCount(failCount);

        /*待审核用户*/
        long reviewCount = sysUserNeedMapper.selectSysUserNeedAuditList();
        statistics.setReviewCount(reviewCount);

        /*供给方用户*/
        statistics.setSupplyCount(sysUserMapper.selectSysUserBySupply());

        /*需求方用户*/
        statistics.setNeedCount(sysUserMapper.selectSysUserByNeed());

        /*审核过的用户*/
        statistics.setExaminedCount(sysUserMapper.selectSysUserByExamined());
        /*注销用户*/
        statistics.setLogoutCount(sysUserMapper.selectSysUserByLogout());

        /*创建时间*/
        statistics.setCreateTime(DateUtils.getNowDate());


        userStatisticsMapper.insertUserStatistics(statistics);
    }

    @Resource
    private UserReserveParkMapper userReserveParkMapper;

    public void spaceStatistics(){
        SpaceStatistics statistics = new SpaceStatistics();

        /*园区*/
        long park = userReserveParkMapper.selectParkListAllCount();
        statistics.setParkCnt(park);
        /*楼宇商用*/
        statistics.setBuildCnt(userReserveParkMapper.selectBuildingListAllCount(null));
        statistics.setBuildSupplyCnt(userReserveParkMapper.selectBuildingListAllCount(0));
        statistics.setBuildNeedCnt(userReserveParkMapper.selectBuildingListAllCount(1));
        /*仓库*/
        statistics.setWareCnt(userReserveParkMapper.selectWarehouseListAllCount(null));
        statistics.setWareSupplyCnt(userReserveParkMapper.selectWarehouseListAllCount(0));
        statistics.setWareNeedCnt(userReserveParkMapper.selectWarehouseListAllCount(1));
        /*厂房*/
        statistics.setWshopCnt(userReserveParkMapper.selectWorkShopListAllCount(null));
        statistics.setWshopSupplyCnt(userReserveParkMapper.selectWorkShopListAllCount(0));
        statistics.setWshopNeedCnt(userReserveParkMapper.selectWorkShopListAllCount(1));
        /*公寓*/
        statistics.setApartmentCnt(userReserveParkMapper.selectApartmentListAllCount(null));
        statistics.setApartmentSupplyCnt(userReserveParkMapper.selectApartmentListAllCount(0));
        statistics.setApartmentNeedCnt(userReserveParkMapper.selectApartmentListAllCount(1));
        /*拍卖*/
        statistics.setAuctionCnt(userReserveParkMapper.selectAuctionListAllCount(null));
        statistics.setAuctionSupplyCnt(userReserveParkMapper.selectAuctionListAllCount(0));
        statistics.setAuctionNeedCnt(userReserveParkMapper.selectAuctionListAllCount(1));
        /*土地*/
        statistics.setLandCnt(userReserveParkMapper.selectLandListAllCount(null));
        statistics.setLandSupplyCnt(userReserveParkMapper.selectLandListAllCount(0));
        statistics.setLandNeedCnt(userReserveParkMapper.selectLandListAllCount(1));


        statistics.setCreateTime(DateUtils.getNowDate());
        spaceStatisticsMapper.insertSpaceStatistics(statistics);
    }
}
